<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/taglib_include.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, target-densitydpi=medium-dpi, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<link href="${ctx}/css/layout.css?ver=${layout_css_version}" rel="stylesheet" type="text/css" />
<title>${projectTitle }</title>
</head>
<body>
  <header id="main-top">订单列表</header>
  <div id="container">
    <c:forEach items="${orderlist}" var="order" varStatus="status">
      <div class="order-list">
        <span>订单号：${order.orderpnr}</span>
      </div>
      <a href="javascript:void(0);" id="${status.index}">
  	    <div class="order-information">
  	      <div class="Originating-station">${order.startStationName}-${order.arriveStationName}</div>
  	      <div class="order-status">${cf:orderStatusName(order.statusCode)}</div>
  	      <div class="Shift-type">${cf:schTypeName(order.schType) }</div>
  	      <div class="Departure-time">${order.leaveDate} ${order.leaveTime}</div>
  	      <div class="number-s">票${order.ticketCount}张
  	         <c:if test="${freeTicketNumMap[order.orderId] ne 0}">
  	             (免票携童${freeTicketNumMap[order.orderId]})
  	         </c:if> 
  	      </div>
  	      <div class="price-s">￥${order.totalPrice}</div>
  	    </div>
  	    <input type="hidden" id="orderId${status.index}" value="${order.orderId}">
        <input type="hidden" id="statusCode${status.index}" value="${order.statusCode}">
      </a>
    </c:forEach>
    <c:if test="${pageCount == 0}">
      <div id="Nticket-tip" style="text-align:center;padding-top:15px;font-size:22pt;color:black;">
            无订单记录！
      </div>
    </c:if>
  </div>
  <c:if test="${pageCount > 0}">
  <div id="container-paging">
    <div class="container-paging-back">
        <a href="${ctx}/order/list.do?pageNow=1" id="first" style="display: block;">|&lt;</a>
    </div>
    <div class="container-paging-back">
        <a href="${ctx}/order/list.do?pageNow=${pageNow - 1}" id="previous">&lt;</a>
    </div>
     <div class="container-paging-select">${pageNow}/${pageCount}</div>
     <div class="container-paging-next">
        <a id="end" href="${ctx}/order/list.do?pageNow=${pageCount}">&gt;|</a>
     </div>
     <div class="container-paging-next">
        <a id="next" href="${ctx}/order/list.do?pageNow=${pageNow + 1}">&gt;</a>
     </div>
   </p>
  </div>
  </c:if>
  <%@ include file="/WEB-INF/views/loading.jsp"%>
  <script type="text/javascript" src="${ctx}/js/jquery.min.js?ver=${jquery_min_version}"></script>
  <script type="text/javascript" src="${ctx}/js/custom.js?ver=${custom_version}"></script>
  <script type="text/javascript">
      $(function(){
    	  var pageNow = ${pageNow};
    	  var pageCount = ${pageCount};
    	  if(pageNow == "1"){
    		  $("#first").removeAttr("href");
    		  $("#previous").removeAttr("href");
    	  }
    	  if(pageNow == pageCount){
    		  $("#next").removeAttr("href");
              $("#end").removeAttr("href");
    	  }
    	  var length = $(".order-list").length;
    	  var boundpassenger = ${constant.order_status_boundpassenger};
    	  var unpaid = ${constant.order_status_unpaid};
    	  var booking = ${constant.order_status_booking};
    	  var haspassenger = ${constant.has_passenginfo};
    	  var nopassenger = ${constant.no_passenginfo};
    	  
    	  $("div[id='container'] a").click(function(){
    		  var id = $(this).attr("id");
    		  var status = $("#statusCode"+id).val();
    		  var orderId = $("#orderId"+id).val();
    		
    		  if (status == unpaid || status == booking || status == boundpassenger) {
    			  var url = "${ctx}/order/haspassengerinfo.do?orderId=" + orderId;
    			  $.ajax({
                      type: "GET",
                      url : url,
                      success:function (data){         
                         if(data.haspassengerinfo == haspassenger) {
                        	 var url = "${ctx}/pay/confirm.do?orderId=" + orderId + "&ptiks=" + data.ptiks;
                        	 window.location.href = url;
                         } else if(data.haspassengerinfo == nopassenger) {
                        	 var url = "${ctx}/order/detail2addpassenger.do?orderId=" + orderId + "&refer=${constant.refer_orderdetail}&pageNow=${pageNow}";
                             window.location.href = url;
                         }
                      }
                  });
    		  } else {
                  var url = "${ctx}/order/detail.do?orderId="+ orderId + "&pageNow=${pageNow}";
                  $(this).attr("href",url);
    		  }
    	  });
 
      });
      if (sessionStorage.pagecount) {
    	  sessionStorage.pagecount = Number(sessionStorage.pagecount) + 1;
      } else {
    	  sessionStorage.pagecount = 1;
          // 保存出发站参数
          localStorage.starting = "${starting}";
          localStorage.startCityId = "${startCityId}";
          localStorage.startStationId = "${startStationId}";
          localStorage.startStationsDisabled = "${startStationsDisabled}";
          if ("${appVer}" == "${constant.appver_nc}" || "${appVer}" == "${constant.appver_ylns}") {
        	  localStorage.groupId = "${constant.groupId_nc}";
          } else {
        	  localStorage.groupId = "";
          }
      }

      if ("${appVer}" == "${constant.appver_nc}" || "${appVer}" == "${constant.appver_ylns}") {
    	  sessionStorage.indexncUrl = "${ctx}/indexnc/index.do?ver=${appVer}";
      }
  </script>
</body>
</html>